// 发送ajax请求，获取用户的信息； 渲染页面（设置头像、设置用户名）
function getUserInfo() {
  $.ajax({
    url: "/my/userinfo",
    success: function (res) {
      if (res.status === 0) {
        let name = res.data.nickname || res.data.username;
        $(".username").text(name);
        if (res.data.user_pic) {
          $(".layui-nav-img").attr("src", res.data.user_pic).show();
          $(".text-head").hide();
        } else {
          let first = name.substr(0, 1).toUpperCase();
          $(".text-head").text(first).css("display", "inline-block");
          $(".layui-nav-img").hide();
        }
      }
    },
  });
}

getUserInfo();

//---------------------------- 退出按钮 --------------------------
$("#exit").on("click", function () {
  layer.confirm("你确定要退出吗?", function (index) {
    setTimeout(function () {
      localStorage.clear("token");
      location.href = "/login.html";
    }, 500);
    layer.msg("退出成功!")
    layer.close(index);
  });
});
